package classes
{
	import events.DirectoryEvent;
	import events.ListingEvent;
	import events.PropertyEvent;
	
	import flash.events.EventDispatcher;
	
	import mx.collections.ArrayCollection;
	
	public class EventGateway extends EventDispatcher
	{
		private static var instance:EventGateway;
		private static var allowIstantiation:Boolean = false;		
		
		public function EventGateway() 
		{
			if(allowIstantiation){
				
			}
		}
		
		public static function getInstance():EventGateway{
			if(instance == null){
				trace("Properties - singleton not instantiated, running constructor");
				allowIstantiation = true;
				instance = new EventGateway();
			}
			return instance;
		}
		
		/** Event Registers **/
		public function registerListDirectoryEventListener():String{
			return ListingEvent.LIST_DIRECTORY;
		}

		public function registerListFileEventListener():String{
			return ListingEvent.LIST_FILE;
		}

		public function registerListChangeDirectoryEventListener():String{
			return DirectoryEvent.DIRECTORY_CHANGED;
		}
		
		public function registerRefreshEvent():String{
			return DirectoryEvent.REFRESH;
		}
		
		public function registerPropertiesSetEvent():String{
			return PropertyEvent.PROPERTIES_LOADED;
		}
		
		
		/** Event Dispatchers **/
		public function dispatchListDirectoryEvent(data:ArrayCollection):void{
			this.dispatchEvent(new ListingEvent(ListingEvent.LIST_DIRECTORY,data));
		}
		
		public function dispatchListFileEvent(data:ArrayCollection):void{
			this.dispatchEvent(new ListingEvent(ListingEvent.LIST_FILE,data));
		}
		
		public function dispatchDirectoryChangedEvent(currentDir:String):void{
			this.dispatchEvent(new DirectoryEvent(DirectoryEvent.DIRECTORY_CHANGED,currentDir));
		}
		
		public function dispatchRefreshEvent():void{
			this.dispatchEvent(new DirectoryEvent(DirectoryEvent.REFRESH));
		}
		
		public function dispatchPropertyChangedEvent():void{
			this.dispatchEvent(new PropertyEvent(PropertyEvent.PROPERTIES_LOADED));
		}
				

	}
}